package com.gmq.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;


public class JwtUtils {
    //生成token
    public String getToken(String key,Map<String, Object> map) {
        String token = Jwts.builder().signWith(SignatureAlgorithm.HS256, key).
                setClaims(map).
                setExpiration(new Date(System.currentTimeMillis() + 43200 * 1000)).compact();
        return token;
    }

    //解析token
    public Claims parseJwt(String key,String token) {
        Claims parseToken = Jwts.parser().
                setSigningKey(key).
                parseClaimsJws(token).
                getBody();
        return parseToken;
    }
}
